package com.qf.air.core.service.impl;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.qf.air.core.client.AirSearchClient;
import com.qf.air.core.service.ElasticsearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Map;

/**
 * @author 何星宇
 * @version V1.0
 * @Date 2021/11/8 11:29
 */

@Service
public class ElasticsearchServiceImpl implements ElasticsearchService {

//    @Autowired
//    private RestTemplate restTemplate;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private AirSearchClient airSearchClient;

    @Override
    public String findAirIndex(Map map) throws IOException {
//        String params = objectMapper.writeValueAsString(map);
//        HttpHeaders httpHeaders = new HttpHeaders();
//        httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
//        HttpEntity httpEntity = new HttpEntity(params, httpHeaders);
//        String result = restTemplate.postForObject("http://localhost:9200/search/airList", httpEntity, String.class);
        String result = airSearchClient.list(map);

        return result;
    }

    @Override
    public String echarts() {
        return airSearchClient.echarts();
    }
}
